<template>
  <div class="recommend-main-left">
    <net-card>
      <template #title>热门推荐</template>
      <div class="playlist-box">
        <template v-for="item in firstPlaylists" :key="item.id">
          <net-playlist
            :src="item.coverImgUrl"
            :count="item.playCount"
            :text="item.description"
          />
        </template>
      </div>
      <div class="playlist-box">
        <template v-for="item in secondPlaylists" :key="item.id">
          <net-playlist
            :src="item.coverImgUrl"
            :count="item.playCount"
            :text="item.description"
          />
        </template>
      </div>
    </net-card>
    <net-card>
      <template #title>新碟上架</template>
      <net-new-disc :discs="newAlbums" />
    </net-card>
    <net-card>
      <template #title>榜单</template>
      <net-rank :datas="rankDatas" />
    </net-card>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted } from 'vue'
import { useStore } from 'vuex'

import { getAllRanks } from '@/hooks'

import NetCard from '@/components/card'
import NetPlaylist from '@/components/playlist'
import NetNewDisc from '@/components/new-disc'
import NetRank from '@/components/rank'

export default defineComponent({
  components: {
    NetCard,
    NetRank,
    NetNewDisc,
    NetPlaylist
  },
  setup() {
    const store = useStore()
    onMounted(async () => {
      store.dispatch('searchMusic/getHotPlaylistAction', {
        limit: 4,
        offset: 0
      })
      store.dispatch('searchMusic/getHotPlaylistAction', {
        limit: 4,
        offset: 4
      })
      store.dispatch('searchMusic/getNewAlbumAction')
      store.dispatch('searchMusic/getRanksAction')

      const ids = await getAllRanks()
      store.dispatch('searchMusic/getRanksDetailsAction', ids[0])
      store.dispatch('searchMusic/getRanksDetailsAction', ids[1])
      store.dispatch('searchMusic/getRanksDetailsAction', ids[2])
    })

    const firstPlaylists = computed(
      () => store.state.searchMusic.hotPlaylist[0]
    )
    const secondPlaylists = computed(
      () => store.state.searchMusic.hotPlaylist[1]
    )
    const newAlbums = computed(() => [
      store.state.searchMusic.newAlbum_first,
      store.state.searchMusic.newAlbum_second
    ])
    const rankDatas = computed(() => store.state.searchMusic.rankPartsDetails)

    return {
      rankDatas,
      newAlbums,
      firstPlaylists,
      secondPlaylists
    }
  }
})
</script>

<style scoped lang="less">
.recommend-main-left {
  width: 70%;
  height: 100%;
  margin-bottom: 3  0px;
  border-right: 1px solid #ccc;
  overflow: hidden;
  .playlist-box {
    width: 100%;
    height: 160px;
    display: flex;
    justify-content: space-between;
  }
}
</style>
